<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@taglib prefix="s" uri="http://www.springframework.org/tags" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>审核页面</title>
    <jsp:include page="../../head.jsp"/>
</head>
<script type="text/javascript">
    var formSetting = {
        title: "注册审核数据",
        module: 'save',
        numCount: '3',
        columns: [{
            index: "auditId",
            name: "auditId",
            label: "auditId",
            hidden: true
        }, {
            index: "arefId",
            name: "arefId",
            label: "arefId",
            hidden: true
        }, {
            index: "comName",
            name: "comName",
            readonly: true,
            label: "公司名称"
        }, {
            index: "comUniteCode",
            name: "comUniteCode",
            readonly: true,
            label: "统一社会信用代码"
        }, {
            index: "comCustomCode",
            name: "comCustomCode",
            readonly: true,
            label: "海关企业注册代码"
        }, {
            index: "contractor",
            name: "contractor",
            readonly: true,
            label: "联系人"
        }, {
            index: "contractPhone",
            name: "contractPhone",
            readonly: true,
            label: "联系人电话"
        }, {
            index: "email",
            name: "email",
            readonly: true,
            label: "邮箱"
        }, {
            index: "comAddress",
            name: "comAddress",
            readonly: true,
            label: "公司地址",
            colspan: "3"
        }, {
            index: "recommendSup",
            name: "recommendSup",
            readonly: true,
            label: "推荐报关行"
        }, {
            index: "supAuditStatus",
            name: "supAuditStatus",
            label: "报关行审核",
            readonly: true
        }, {
            index: "supAuditTime",
            name: "supAuditTime",
            formatter: 'date',
            formatoptions: {
                srcformat: 'Y-m-d H:i:s',
                newformat: 'Y-m-d H:i:s'
            },
            readonly: true,
            label: "报关行审核时间"
        }, {
            index: "supReamrk",
            name: "supReamrk",
            readonly: true,
            label: "报关行审核反馈",
            colspan: "3"
        }, {
            index: "agentComName",
            name: "agentComName",
            label: "代录单人",
            readonly: true
        }, {
            index: "pmanagerAuditStatus",
            name: "pmanagerAuditStatus",
            label: "平台审核",
            readonly: true
        }, {
            index: "pmanagerAuditTime",
            name: "pmanagerAuditTime",
            formatter: 'date',
            formatoptions: {
                srcformat: 'Y-m-d H:i:s',
                newformat: 'Y-m-d H:i:s'
            },
            readonly: true,
            label: "平台审核时间"
        }, {
            index: "pmanagerRemark",
            name: "pmanagerRemark",
            type: "textarea",
            colspan: "3",
            label: "平台审核反馈"
        }],
        form: {
            'url': 'approve-saveOrUpdate',
            'data': function () {
                var dataValue = null;
                $.ajax({
                    url: "auditComData?registerType=${param.registerType}&auditId=${param.auditId}",
                    async: false,
                    cache: false,
                    success: function (data) {
                      dataValue = data;
                    }
                });
                return dataValue;
            },
            'afterAjaxSuccess': function (responseText, statusText, xhr, $form) {
                /*做了审核以后有让去直接去更新左侧的数据 不去后台取  直接减一*/
                try {
                    // window.top.regCountReminder.Count__ = (window.top.regCountReminder.Count__ - 1);
                    // window.top.regCountReminder.load();
                } catch (exe) {
                }
            }
        },
        buttons: {
            custom: [
                {
                    id: "passBtn",
                    value: "通过审核",
                    click: function () {
                        var registerType = '${param.registerType}';
                        if("直接注册" === registerType){
                            var supStatus = $("input[name=supAuditStatus]").val();
                            var recommendSup = $("input[name=recommendSup]").val();
                            if(recommendSup !== ""){
                                if(supStatus === ""){
                                    layer.alert("推荐报关行尚未审核，应该由推荐报关行先审核!");
                                    return;
                                }else if(supStatus === "不通过"){
                                    layer.alert("该注册公司推荐报关行审核不通过");
                                    return;
                                }
                            }
                        }
                        didAudit(1);
                    }
                },
                {
                    id: "rejectBtn",
                    value: "审核不通过",
                    click: function () {
                        var registerType = '${param.registerType}';
                        if("直接注册" === registerType){
                            //不通过审核，系统注册
                            var supStatus = $("input[name=supAuditStatus]").val();
                            var recommendSup = $("input[name=recommendSup]").val();
                            if(recommendSup !== ""){
                                if(supStatus === ""){
                                    layer.alert("推荐报关行尚未审核，应该由推荐报关行先审核!");
                                    return;
                                }else if(supStatus === "不通过"){
                                    layer.alert("该注册公司推荐报关行审核不通过");
                                    return;
                                }
                            }
                        }
                        didAudit(0);
                    }
                }, {
                    id: "cancelbtn",
                    value: "返回",
                    click: function () {
                        history.go(-1);
                    }
                }]
        }
    };
    var gridSetting = {
        grid: {
            id: "attachmentGrid",
            title: "已提交附件",
            url: "<s:url value='/order/getAttachmentForAudit'/>?auditId=${param.auditId}",
            colModel: [{
                index: "name",
                name: "name",
                label: "文件名",
                formatter: function (val, opts, row) {
                    if (val) {
                        return "<a href='javascript:downloadAtta(\"" + row.id + "\")'>"
                               + val + "</a>"
                    } else {
                        return "";
                    }
                }
            }, {
                index: "ctime",
                name: "ctime",
                label: "上传时间"
            }]
        }
    };
    $(document)
        .ready(
            function () {
                if('直接注册' === '${param.registerType}'){
                    $("#uploadFrame").show();
                } else {
                    $("#attachmentsTable").mrdForm(gridSetting);
                }
                $("#formtable").mrdForm(formSetting);
                $("#saveButton").remove();
                if($("input[name='pmanagerAuditStatus']").val() !== ''){
                    $("#passBtn").remove();
                    $("#rejectBtn").remove();
                }
            });

    function didAudit(pass){
        $.ajax({
           url:"didComAudit",
           method:"post",
           data:{registerType:'${param.registerType}', auditId: '${param.auditId}', pass:pass, remark:$("textarea[name=pmanagerRemark]").val()},
           dataType:"json",
           success:function(result){
               layer.alert(result.msg, function(){
                   if(result.result){
                       history.go(-1);
                   }else{
                       layer.closeAll();
                   }
               });
           }
       });
    }

    function downloadAtta(id) {
        var url = "/order/downloadComAttachment?id=" + id;
        $.download(url);
    }
</script>
<body>
<div style="width: 100%;padding:auto;">
    <div id="formtable"></div>
    <div id="attachmentsTable"></div>
    <iframe id="uploadFrame" src="/business/uploadMain?type=reg#${param.auditId}" height=250 style="display: none;"
            width=98% frameborder="no" border="0" marginwidth="0" marginheight="0" ></iframe>
</div>
</body>
</html>
